﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXIMEW.DAL.Base;
using ZXIMEW.Models.DModels;

namespace ZXIMEW.DAL
{
    public class MenuDAL : BaseDAL<MenuInfo>
    {
        /// <summary>
        /// 指定的菜单列表
        /// </summary>
        /// <param name="roleIds"></param>
        /// <param name="pId">菜单等级 0--一级菜单</param>
        /// <param name="isAdmin"></param>
        /// <returns></returns>
        public List<MenuInfo> GetMenus(List<int> roleIds, int pId, bool isAdmin)
        {
            string strWhere = $"ParentId={pId}";
            if (!isAdmin)
            {
                string strIds = string.Join(",", roleIds);
                strWhere += $"and MenuId in (select MenuId from RoleMenuInfos where RoleId in ({strIds}))";
            }
            return GetModelList(strWhere, "MenuId,MenuName,FrmName,MOrder,MenuCode,isTop", "MOrder");
        }
    }
}
